# vim: filetype=yaml sw=2
version: '[% c("abbrev") %]'
git_url: https://github.com/keroserene/go-webrtc.git
git_hash: 90ac15ae07cc6e820cd922a239dd892598986622
filename: '[% project %]-[% c("version") %]-[% c("var/osname") %]-[% c("var/build_id") %].tar.gz'

build: '[% c("projects/go/var/build_go_lib") %]'

var:
  container:
    use_container: 1
  go_lib: github.com/keroserene/go-webrtc
  build_go_lib_pre: |
    [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
    [% IF c("var/linux") %]
      tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/binutils') %]
      export PATH="/var/tmp/dist/binutils/bin:$PATH"
    [% END -%]
    tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/webrtc') %]
    # Replace the prebuilt webrtc library with our own one.
    rm -rf include/ lib/
    cp -a /var/tmp/dist/webrtc/{include,lib} .
    [% IF c("var/linux") -%]
      # The go-webrtc package sets _GLIBCXX_USE_CXX11_ABI=0 for compatibility with
      # the prebuilt libwebrtc-magic.a libraries. Since we build our own
      # libwebrtc-magic.a with the C++11 ABI, we have to undo that setting here,
      # using CGO_CXXFLAGS.
      # __STDC_FORMAT_MACROS is needed for a definition of PRIxPTR from inttypes.h.
      export CGO_CXXFLAGS="-D_GLIBCXX_USE_CXX11_ABI=1 -D__STDC_FORMAT_MACROS=1"
      export CGO_LDFLAGS=-latomic
    [% END -%]
    [% IF c("var/osx") -%]
      export CGO_ENABLED=1
      export CGO_CFLAGS="[% c("var/FLAGS") %] -mmacosx-version-min=10.7"
      export CGO_CXXFLAGS="[% c("var/FLAGS") %] -stdlib=libc++ -mmacosx-version-min=10.7"
      export CGO_LDFLAGS="[% c("var/FLAGS") %] -stdlib=libc++ -mmacosx-version-min=10.7"
      export CC="$clangdir/bin/clang"
      export CXX="$clangdir/bin/clang++"
    [% END -%]

targets:
  master:
    git_hash: master
  linux:
    var:
      arch_deps:
        - pkg-config
        - libx11-dev
  osx-x86_64:
    var:
      arch_deps:
        - pkg-config

input_files:
  - project: container-image
  - name: go
    project: go
  - name: webrtc
    project: webrtc
  - name: '[% c("var/compiler") %]'
    project: '[% c("var/compiler") %]'
  - name: binutils
    project: binutils
    enable: '[% c("var/linux") %]'
